{include file="public/header" /}
<style type="text/css">
    .js-sort{
        width: 80px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">菜单列表</a></li>
        <li><a href="{:url('authRule/add', array('action' => 'add') )}">添加菜单</a></li>
    </ul>

    <table class="table table-hover table-bordered table-list margin-top-20">
        <thead>
        <tr>
            <th>ID</th>
            <th>菜单名称</th>
            <th>控制器方法</th>
            <th>状态</th>
            <th>图标代码</th>
            <th>排序</th>
            <th>更新时间</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        {foreach name="list" item="vo"}
            <tr>
                <td>{$vo.id}</td>
                <td>{$vo.name}</td>
                <td>{$vo.controllerAction}</td>
                <td>
                    {if condition="$vo['status'] eq '1'"}
                        启用
                    {else /}
                        禁用
                    {/if}
                </td>
                <td>{$vo.icon}</td>
                <td>
                    <input type="text" value="{$vo.sort}" class="input-order valid js-sort" data-id="{$vo.id}"/>
                </td>
                <td>{$vo.modifyTime}</td>
                <td>{$vo.createTime}</td>
                <td>
                    <a href="{:url('authRule/edit',array('action' => 'edit', 'id' => $vo['id']))}">编辑</a>
                </td>
            </tr>

            {foreach name="$vo['children']" item="vo2"}
                <tr>
                    <td>{$vo2.id}</td>
                    <td> └────{$vo2.name}</td>
                    <td>{$vo2.controllerAction}</td>
                    <td>
                        {if condition="$vo2['status'] eq '1'"}
                        启用
                        {else /}
                        禁用
                        {/if}
                    </td>
                    <td>{$vo2.icon}</td>
                    <td>
                        <input type="text" value="{$vo2.sort}" class="input-order valid js-sort" data-id="{$vo2.id}"/>
                    </td>
                    <td>{$vo2.modifyTime}</td>
                    <td>{$vo2.createTime}</td>
                    <td>
                        <a href="{:url('authRule/edit',array('action' => 'edit', 'id' => $vo2['id']))}">编辑</a>
                    </td>
                </tr>
                {foreach name="$vo2['children']" item="vo3"}
                    <tr>
                        <td>{$vo3.id}</td>
                        <td> └──────────{$vo3.name}</td>
                        <td>{$vo3.controllerAction}</td>
                        <td>
                            {if condition="$vo3['status'] eq '1'"}
                            启用
                            {else /}
                            禁用
                            {/if}
                        </td>
                        <td>{$vo2.icon}</td>
                        <td>
                            <input type="text" value="{$vo3.sort}" class="input-order valid js-sort" data-id="{$vo3.id}"/>
                        </td>
                        <td>{$vo3.modifyTime}</td>
                        <td>{$vo3.createTime}</td>
                        <td>
                            <a href="{:url('authRule/edit',array('action' => 'edit', 'id' => $vo3['id']))}">编辑</a>
                        </td>
                    </tr>
                {/foreach}
            {/foreach}
        {/foreach}
    </table>
</div>
<script src="/static/admin/js/admin.js"></script>
<script src="/static/admin/js/layer/layer.js"></script>
<script>
    $(function () {
        $(".js-sort").blur(function () {
            var sort = this.value;
            var id = $(this).data('id');
            $.post("{:url('authRule/updateSort')}", {id:id,sort:sort}, function (res) {
                if(res.errorCode === 200){
                    layer.confirm(res.message, {
                        btn:['确认','取消'],
                        success:function(){
                            this.enterEsc = function (event) {
                                if (event.keyCode === 13) {
                                    $(".layui-layer-btn0").click();
                                    return false;
                                }
                            };
                            $(document).on('keydown', this.enterEsc);

                            $(".layui-layer-btn0").on("click",function() {
                                window.location.reload();
                                return false
                            })
                        },
                        end:function(){
                            $(document).off('keydown',this.enterEsc);
                        }
                    });
                }else{
                    layer.alert(res.message, {
                        title: '提示',
                        icon: 2
                    });
                }
            },'json');
        });
    });
</script>
</body>
</html>